<% layout('/layouts/default.html', {title: '库存检验单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('库存检验单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btn-check" title="${text('检验')}"><i class="fa fa-filter"></i> ${text('检验')}</a>
				<a href="#" class="btn btn-default" id="btn-history" title="${text('检验历史')}"><i class="fa fa-filter"></i> ${text('检验历史')}</a>
				<script>
                    $("#btn-history").click(function () {
                        js.addTabPage($(this),"检验历史","${ctx}/st/stStockCheckHistory");
                    })
					$("#btn-check").click(function (){
						var rowIdArr=$('#dataGrid').dataGrid('getSelectRows');
						js.layer.open({
							type: 2,
							area: ['400px', '500px'],
							title: '${text("导入用户数据")}',
							resize: false,
							scrollbar: true,
							content: "${ctx}/st/stStockCheckBill/checkForm",
							success: function (layero, index) {
								layero.find('input[type="checkbox"]').iCheck();
							},
							btn: ['<i class="fa fa-check"></i> ${text("导入")}',
								'<i class="fa fa-remove"></i> ${text("关闭")}'],
							btn1: function (index, layero) {
								var win = layero.iframeWindow();
								var params = win.commit();
								if(params.checkResult ==1){
								    js.showMessage("不能是未检验");
								    return false;
                                }
								$.ajax({
									url:"${ctx}/st/stStockCheckBill/check",
									dataType:'json',
									type:'POST',
									data:{
										//请求参数
										checkType:params.checkResult,
										checkDesc:params.checkDesc,
										id:rowIdArr.join(",")
									},
									success:function(result){

									}
								});
								return true;
							}
						});
					});
				</script>
<!--				<% if(hasPermi('st:stStockCheckBill:edit')){ %>-->
<!--					<a href="${ctx}/st/stStockCheckBill/form" class="btn btn-default btnTool" title="${text('新增库存检验单')}"><i class="fa fa-plus"></i> ${text('新增')}</a>-->
<!--				<% } %>-->
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${stStockCheckBill}" action="${ctx}/st/stStockCheckBill/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('产品编码')}：</label>
					<div class="control-inline">
						<#form:input path="productCode" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('产品名称')}：</label>
					<div class="control-inline">
						<#form:input path="productName" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('批次号')}：</label>
					<div class="control-inline">
						<#form:input path="batchNumber" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('条码号')}：</label>
					<div class="control-inline">
						<#form:input path="barCode" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('件数')}：</label>
					<div class="control-inline">
						<#form:input path="caseNumber" maxlength="5" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('包装规格')}：</label>
					<div class="control-inline">
						<#form:input path="packType" maxlength="3" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('库存数量')}：</label>
					<div class="control-inline">
						<#form:input path="stockNumber" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('检验结果')}：</label>
					<div class="control-inline width-120">
						<#form:select path="checkType" dictType="st_stock_check_state" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('检验描述')}：</label>
					<div class="control-inline">
						<#form:input path="checkDesc" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('入库日期')}：</label>
					<div class="control-inline">
						<#form:input path="inStockDate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('备注信息')}：</label>
					<div class="control-inline">
						<#form:input path="remarks" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	var allData;
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("产品编码")}', name:'productCode', index:'a.product_code', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return val;//'<a href="${ctx}/st/stStockCheckBill/form?id='+row.id+'" class="btnList" data-title="${text("编辑库存检验单")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("产品名称")}', name:'productName', index:'a.product_name', width:150, align:"left"},
		{header:'${text("批次号")}', name:'batchNumber', index:'a.batch_number', width:150, align:"left"},
		{header:'${text("条码号")}', name:'barCode', index:'a.bar_code', width:150, align:"left"},
		{header:'${text("件数")}', name:'caseNumber', index:'a.case_number', width:150, align:"center"},
		{header:'${text("包装规格")}', name:'packType', index:'a.pack_type', width:150, align:"left"},
		{header:'${text("库存数量")}', name:'stockNumber', index:'a.stock_number', width:150, align:"center"},
		{header:'${text("检验结果")}', name:'checkType', index:'a.check_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_stock_check_state')}, val, '${text("未知")}', true);
		}},
		{header:'${text("检验描述")}', name:'checkDesc', index:'a.check_desc', width:150, align:"left"},
		{header:'${text("入库日期")}', name:'inStockDate', index:'a.in_stock_date', width:150, align:"center"},
		{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('st:stStockCheckBill:edit')){ %>
				actions.push('<a href="${ctx}/st/stStockCheckBill/form?id='+row.id+'" class="btnList" title="${text("编辑库存检验单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				// actions.push('<a href="${ctx}/st/stStockCheckBill/delete?id='+row.id+'" class="btnList" title="${text("删除库存检验单")}" data-confirm="${text("确认要删除该库存检验单吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	showCheckbox: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		allData=data.list;
	}
});
function getSelectData(){
	var rowIdArr=$('#dataGrid').dataGrid('getSelectRows');
	// console.info("rowID",rowIdArr);
	// var select=$('#dataGrid').dataGrid('getRowData', rowId);
	// select['id']=rowId;
	var select=[];
	for(var index in allData){

		var item=allData[index];
		if(-1 != rowIdArr.indexOf(item.id)){
			select.push(item);
		}
	}
	return select;
}
</script>